package repository

import (
	"context"

	"gitee.com/thewalkers/refactoring-code/model"
	"github.com/jmoiron/sqlx"
	"go.uber.org/zap"
)

// MysqlCommissionedClassificationRepository is data/repository implementation
// of service layer EmployeeRepository
type MysqlCommissionedClassificationRepository struct {
	DB *sqlx.DB
}

// NewEmployeeRepository is a factory for initializing Employee Repository
func NewCommissionedClassificationRepository(db *sqlx.DB) model.CommissionedClassificationRepository {
	return &MysqlCommissionedClassificationRepository{
		DB: db,
	}
}

// Update update by id
func (m *MysqlCommissionedClassificationRepository) Update(ctx context.Context, c *model.CommissionedClassification) error {
	query := `UPDATE commissioned_classification SET commission_rate = ?, salary = ? WHERE payment_classification_id = ?`
	if _, err := m.DB.Exec(query, c.CommissionRate, c.Salary, c.PaymentClassificationID); err != nil {
		zap.L().Error("repository cound not get a employee with err: ", zap.Error(err))
		return err
	}

	return nil
}
